package com.ujson.chat.server.builder;

import com.ujson.chat.common.proto.MessageProto;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * <h3>ujson-parent</h3>
 * <p>消息转发结果构造器</p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-26 19:46
 */
@Slf4j
@Service
public class MessageResponseBuilder extends AbstractBuilder {
    private static MessageResponseBuilder messageResponseBuilder;

    @PostConstruct
    public void init() {
        messageResponseBuilder = this;
    }

    public static MessageResponseBuilder inst() {
        return messageResponseBuilder;
    }

    @Override
    public MessageProto.MessageType getType() {
        return MessageProto.MessageType.MESSAGE_RESPONSE;
    }

    public MessageProto.Message build(ChannelHandlerContext ctx, MessageProto.MessageRequest message) {
        return commonBuild(ctx).toBuilder()
                .setMessageRequest(message)
                .build();
    }
}
